package com.ufo.store.management.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.ufo.store.management.R;
import com.ufo.store.management.adapter.Isszmbalv3PayFlowExpandAdapter;
import com.ufo.store.management.entity.Isszmbalv3PayFlow;
import com.ufo.store.management.entity.Isszmbalv3PayFlowGroup;
import com.ufo.store.management.entity.SerializableList;

import java.util.ArrayList;
import java.util.List;

/**
 *  作者：taoli on 2017/3/1 0001 13:41
 *  
 */
public class Isszmbalv3PayListActivity extends BaseActivity {
    private ExpandableListView mPayFlowListElv;
    private Isszmbalv3PayFlowExpandAdapter statusAdapter;
    private LinearLayout mFailLl;
    private List<Isszmbalv3PayFlowGroup> mIsszmbalv3PayFlowGroupInfoList = new ArrayList<Isszmbalv3PayFlowGroup>();

    private String mSearchDate = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        initView();
        Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
        toolbar.setTitle("销售列表");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.ic_back_selector);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                SerializableList p = (SerializableList) bundle.getSerializable("Isszmbalv3PayFlowGroup");
                mIsszmbalv3PayFlowGroupInfoList = p.getmIsszmbalv3PayFlowGroupInfoList();
                mSearchDate = bundle.getString("Date");
            }
        }
    }

    private void initView() {
        setContentView(R.layout.activity_isszmbalv3_paylist);
        mFailLl = (LinearLayout) findViewById(R.id.get_fail_tip_ly);
        mPayFlowListElv = (ExpandableListView) findViewById(R.id.expandlist);
        statusAdapter = new Isszmbalv3PayFlowExpandAdapter(this, mIsszmbalv3PayFlowGroupInfoList);
        mPayFlowListElv.setAdapter(statusAdapter);
        mPayFlowListElv.setSelection(0);
        // 去掉ExpandableListView 默认的箭头 
        mPayFlowListElv.setGroupIndicator(null);
        int groupCount = mPayFlowListElv.getCount();
        // 首次加载展开第一项
        for( int i = 0; i < groupCount; i++ ){
            mPayFlowListElv.expandGroup(i);
        }
        // return true不能点击收缩   return false 可以点击收缩
        mPayFlowListElv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return false;
            }
        });
        mPayFlowListElv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
                Isszmbalv3PayFlow payFlow = mIsszmbalv3PayFlowGroupInfoList.get(groupPosition).getChildList().get(childPosition);
                Intent toIntent = new Intent(Isszmbalv3PayListActivity.this, Isszmbalv3SaleDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("Flowno", payFlow.payFlowFlow_no);
                toIntent.putExtras(bundle);
                startActivity(toIntent);
                return true;
            }
        });

        if(mIsszmbalv3PayFlowGroupInfoList.size() != 0 ){
            mFailLl.setVisibility(View.GONE);
            mPayFlowListElv.setVisibility(View.VISIBLE);
        }else{
            mFailLl.setVisibility(View.VISIBLE);
            mPayFlowListElv.setVisibility(View.GONE);
        }
    }
}
